# Maintainer: Richard Acayan <mailingradian@gmail.com>
# Stable Linux kernel with patches for SDM670 devices
# Kernel config based on: arch/arm64/configs/{defconfig,sdm{670,845}.config}

_flavor="postmarketos-qcom-sdm670"
pkgname=linux-$_flavor
pkgver=6.12.3
pkgrel=1
pkgdesc="Mainline Kernel fork for SDM670 devices"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/sdm670-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community"
makedepends="
	bash
	bison
	findutils
	flex
	installkernel
	openssl-dev
	perl
	python3
	zstd
"

_config="config-$_flavor.$arch"
_tag="sdm670-v$pkgver"

# Source
source="
	https://gitlab.com/sdm670-mainline/linux/-/archive/$_tag/linux-$_tag.tar.gz
	$_config
"
builddir="$srcdir/linux-$_tag"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot

	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
6f9942e6b30d5bf745a53ed666b3b0e76448a42ffa1962fa31a75dd1a7198ead12f80958ac405877b8e8ef6046486a629fe7d362a1760c3dc496993344b4e1bd  linux-sdm670-v6.12.3.tar.gz
7667d4843f84551f0b17110c5f7f1d0f8a8fc6e1d200578109f53604c8b49b23d84bc4b27c351d24772ef0f776f8d0c57b50f7f04f058d551248e4c4a0bc0298  config-postmarketos-qcom-sdm670.aarch64
"
